home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6027 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.1 KB  |  53 lines

  1. Path: news.wyoming.com!usenet
  2. From: dcromley@wyoming.com (Dave Cromley)
  3. Newsgroups: comp.lang.c++,comp.os.msdos.programmer
  4. Subject: Re: Function Pointers In C++
  5. Date: 11 Feb 1996 18:34:02 GMT
  6. Organization: wyoming.com LLC
  7. Message-ID: <4flcqq$35n@horn.wyoming.com>
  8. NNTP-Posting-Host: cys-cap-4.wyoming.com
  9. Mime-Version: 1.0
  10. X-Newsreader: WinVN 0.99.2
  11.  
  12. Nathan wrote:
  13.  
  14. >I have a class which contains function pointers. ..
  15. >I seem to be having troubles setting these pointers? ..
  16.  
  17. I hope this helps.
  18. I don't understand all I know about this.
  19.  
  20.   Dave C.
  21.  
  22. #include <iostream.h>
  23. typedef char byte;
  24.  
  25. void      func1(int); // function returning void
  26. void far *func2(int); // function returning pointer to void
  27.  
  28. class c_a {
  29.   public: byte far (*Func)(); //  pointer to function returning byte
  30.   c_a::c_a();
  31.   } ;
  32.  
  33. byte b1;
  34.  
  35. void main() {
  36.   c_a c_a1;
  37.   cout << "Hello, world.\n";
  38.   }
  39.  
  40. c_a::c_a() {
  41.  Func = (byte far (*)())func1; // or
  42.  Func = (byte far (*)())func2(9); // I think func2 is your case
  43.  }
  44.  
  45. void      func1(int p) { // function returning void
  46.   }
  47.  
  48. void far *func2(int p) { // function returning pointer to void
  49.   return (void far *) &b1;
  50.   }
  51.  
  52.  
  53.